define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'checkout_goods/index' + location.search,
                    add_url: 'checkout_goods/add',
                    edit_url: 'checkout_goods/edit',
                    del_url: 'checkout_goods/del',
                    multi_url: 'checkout_goods/multi',
                    import_url: 'checkout_goods/import',
                    table: 'checkout_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                      //  {field: 'good_id', title: __('Good_id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'ruku_date', title: __('ruku_Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'goods_sn', title: __('Goods_sn'), operate: 'LIKE'},
                       // {field: 'goods_name', title: __('Goods_name'), operate: 'LIKE'},
                        {field: 'stock', title: __('Stock')},
                        {field: 'weight', title: __('Weight'), operate:'BETWEEN'},
                        {field: 'volume_str', title: __('Volume_str'), operate: 'LIKE'},
                        {field: 'volume', title: __('Volume'), operate:'BETWEEN'},
                        {field: 'pack', title: __('Pack'), operate: 'LIKE'},
                        {field: 'goods_state', title: __('Goods_state'), operate: 'LIKE'},
                        {field: 'wenjian_state', title: __('Wenjian_state'), operate: 'LIKE'},
                        {field: 'ku_number', title: __('Ku_number'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'note', title: __('Note'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        checkout: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
